package string;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;



public class discretizefile {
  public static class bw{
	  public static void write(String s){
		  System.out.println(s);
	  }
	  public static void close(){
		  
	  }
  }
  public static void change(String fristfile,String lastfile)throws IOException{
    ArrayList<String> attstr=new ArrayList<String>();
    
    File f1=new File(fristfile);
    File f2=new File(lastfile);
    
    FileReader in=new FileReader(f1);
    //FileWriter out =new FileWriter(f2);
    
    BufferedReader br=new BufferedReader(in); 
    Map<String,String> mapping  = new HashMap<String,String>();
  //  BufferedWriter bw=new BufferedWriter(out);
    String [] atts;
    String s  = null;
    int  seq = 0;
    while((s=br.readLine())!=null){
      if(s.indexOf("@attribute")>=0){
    	  if(s.indexOf("class {")>=0){
    		  bw.write(s);
    		  continue;
    	  }
	        atts=stringhandle(s);
	        for(int i=1;i<atts.length;i++){
	         attstr.add(atts[i]);
	          mapping.put(atts[i], "A"+(seq++));
        }
        //continue;
      }
      
     
      
      if(attstr.size()>0){
        s=replaceline(attstr, s,mapping);
        
        bw.write(s);
       // bw.newLine();
       // s=br.readLine();   
      }else{
        bw.write(s);
        //bw.newLine();
       // s=br.readLine();   
      }
    }
    bw.close();
	br.close();
  }
  
  public static String[] stringhandle(String s){
    if(s.indexOf("@attribute")==-1){
      return null;
    }else{
      String [] str =s.split("[{,}]");
      return str;
    }

  }
  
  public static String replaceline(ArrayList<String> attstr,String s,Map<String,String> mapping){
   // int i=0;
    //String a="A"+i;
    String result  = s;
    //String result =  null;
    for(String ts:attstr){
     result = result.replace(ts,mapping.get(ts));
     // i++;
    }
    return result;
    
  }
  public static void main(String[] args)throws IOException{
       
//    Scanner sc1=new Scanner(System.in);
//    System.out.println("输入源文件");
//    String uciname=sc1.nextLine();
//    Scanner sc3=new Scanner(System.in);
//    System.out.println("输入目标文件");
//    String wekaarff=sc3.nextLine();

	  
    change(	  discretizefile.class.getResource("wine.arff").getFile(),"out.txt");
    
  }

  
  

}
